package 牛客题霸;

public class 最长公共前缀 {

    public String longestCommonPrefix (String[] strs) {
        if(strs == null || strs.length <= 0) {
            return "";
        }
        String base = strs[0];
        for (int i = 1; i < strs.length; i++) {
            while (strs[i].indexOf(base) != 0) {
                // strs[i].indexOf(base) == 0 退出循环，说明base的字符串是str[i]的最长前缀
                base = base.substring(0,base.length() - 1);
            }
        }
        return base;
    }

    public static void main(String[] args) {

    }
}
